<?php
namespace app\admin\controller;

class Cms extends Base
{
    public function lists()
    {
        $cms=model("cms");
        $list = $cms::where('proxy_id',$this->proxy['id'])->paginate(10);
        $this->assign('list', $list);
        return view();

    }

    public function delete(){
        $id=input("get.id");
        $proxy_id=$this->proxy['id'];
        $cms=model("cms");
        $cms = $cms->get(["id"=>$id,"proxy_id"=>$proxy_id]);
        if($cms!=null){
            $cms->delete();
        }
        $this->redirect("cms/lists");


    }
    public function edit()
    {
        $id=input("get.id");
        $cms=model("cms");


        if(request()->isPost()){
            if($cms->byusername(input("post.username"))!=null && $id==null){
                $this->assign("msg","用户名已存在");
            }
            else{

                $cms['proxy_id']=$this->proxy['id'];
                $cms['createtime']=now();
                if($id!=null){
                    $cms->allowField(true)->save($_POST,['id'=>$id]);
                }
                else{
                    $cms->allowField(true)->save($_POST);
                }
                $this->redirect("cms/lists");

            }

        }
        if($id!=null){
            $info=$cms->get($id);
            $this->assign("info",$info);
        }
        return view();
    }
    public function none()
    {
        return $this->fetch();
    }
}
